package com.bijiawang.user.repository;

import com.bijiawang.user.domin.Nfavorites;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.util.List;

public interface NfavoritesRepository extends JpaRepository<Nfavorites, Integer> {

    //通过goodsId查询最新价格
    Nfavorites findFirstByGoodsIdOrderByOrderNumberDesc(Integer goodsId);
    //通过goodsId查出该商品的所有数据,用于页面显示，遍历的时候除掉第一条数据
    List<Nfavorites> findAllByGoodsIdOrderByOrderNumberAsc(Integer goodsId);
//    @Modifying
//    @Query("update nfavorites set userName=#{newUsername} where userName=#{oldUsername}")
//    public void updateUsername(String oldUsername,String newUsername);
    @Transactional
    public int deleteByGoodsId(int goodsId);
}
